package com.yunpuvip.sachet.modular.system.factory;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.core.base.warpper.BaseControllerWrapper;
import com.yunpuvip.sachet.modular.core.exception.GunsException;
import com.yunpuvip.sachet.modular.core.exception.GunsExceptionEnum;
import com.yunpuvip.sachet.modular.page.LayuiPageInfo;
import org.apache.poi.ss.formula.functions.T;

import java.util.*;

/**
 * @ClassName BeanToListMapFactory
 * @Description TODO
 * @Autor wushaohong
 * @Date 2019/3/21
 * @Version 1.0
 */
public class BeanToListMapFactory {

    public static List<Map<String,Object>> toListMap (List<T> list){
        if(ObjectUtil.isNotNull(list)){
            if(ObjectUtil.length(list)>0){
                ArrayList<Map<String, Object>> arrayList = new ArrayList<>();
                for (Object obj :list) {
                    Map<String, Object> map = BeanUtil.beanToMap(obj);
                    arrayList.add(map);
                }
                return arrayList;
            }else {
                throw new GunsException(GunsExceptionEnum.LIST_ERROR);
            }
        }else {
            throw new GunsException(GunsExceptionEnum.LIST_ERROR);
        }

    }
    public static List<Map<String,Object>> toListMap(LayuiPageInfo pageInfo){
        long count = pageInfo.getCount();
        if(0>=count){
            return null;
        }
        List list = toListMap(pageInfo.getData());
        return list;
    }


}
